package com.wawei.seeds.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.wawei.seeds.R;
import com.wawei.seeds.model.WalnutMainEvent;
import com.wawei.seeds.utils.WalnutUtils;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 *
 * Created by t27891 on 15/6/22.
 */
public class WalnutServiceFragmentAdapter extends SeedsBaseAdapter<WalnutMainEvent> {
    public WalnutServiceFragmentAdapter(Context context) {
        super(context);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = convertView;
        ViewHolder viewHolder;
        if(null == view){
            view = LayoutInflater.from(context).inflate(R.layout.fragment_walnut_me_service_item, parent, false);
            viewHolder = new ViewHolder(view);
            view.setTag(viewHolder);
        }
        else {
            viewHolder = (ViewHolder)view.getTag();
        }

        WalnutMainEvent item = (WalnutMainEvent)getItem(position);
        viewHolder.eventTitle.setText(item.title);
        viewHolder.eventAction.setText(item.action);
        viewHolder.eventAppointment.setText(item.booked);
        viewHolder.appointmentStatus.setText(WalnutUtils.transformServiceStatus(context, item.bookingState));
        viewHolder.eventAvailable.setText(item.available);

        return view;
    }

    static class ViewHolder{
        @InjectView(R.id.item_service_event_action)TextView eventAction;
        @InjectView(R.id.item_service_event_title)TextView eventTitle;
        @InjectView(R.id.item_service_event_appointment)TextView eventAppointment;
        @InjectView(R.id.item_service_event_appointment_status)TextView appointmentStatus;
        @InjectView(R.id.item_service_event_available)TextView eventAvailable;

        public ViewHolder(View view) {
            ButterKnife.inject(this, view);
        }
    }
}
